<template>
  <transition name="dialog-fade">
    <div v-if="visible" class="dialog-mask disable-scroll">
      <div class="box">
        <slot></slot>
        <img
          src="../assets/images/del.png"
          class="images1"
          @click="closeDialog"
          alt=""
        />
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "DialogSb",
  props: {
    title: {
      type: String,
      default: "Dialog",
    },
    visible: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    closeDialog() {
      this.$emit("update:visible", false); // 触发关闭对话框事件
    },
  },
};
</script>

<style scoped>
.box {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.images1 {
  width: 20px;
  margin-top: 15px;
  height: 20px;
}
.dialog-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer; /* 添加光标指示 */
}

.dialog {
  width: 400px;
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease-out; /* 添加过渡效果 */
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h3 {
  margin: 0;
}

.dialog-content {
  margin-top: 20px;
}

.dialog button {
  border: none;
  background: transparent;
  cursor: pointer;
}

/* 添加进入和离开动画 */
.dialog-fade-enter-active,
.dialog-fade-leave-active {
  transition: opacity 0.3s ease-out;
}

.dialog-fade-enter,
.dialog-fade-leave-to {
  opacity: 0;
}

/* 禁止页面滚动 */
.disable-scroll {
  overflow: hidden;
}
</style>
